<?php
	require_once("user.inc");
	require_once("sticky.inc");
	require_once("lib.inc");
	$retVal = array(
		'success' => false,
		'message' => '',
	);		
	$method = getParam('__m');
	$paramArray = getParam('__d');
	if(!is_null($paramArray)){
		$paramArray = json_decode(urldecode(getParam('__d')),true);
	}
	if(!is_null($paramArray) && is_array($paramArray)){
		foreach($paramArray as &$value){
			$value = $rwConn->real_escape_string($value);
		}
	}

	
	$userObj = new User($rwConn);
	$isLoggedInResult = $userObj->isLoggedIn();
	if(!$isLoggedInResult['success']){
		$retVal['message'] = 'You must be logged in.';
		returnAPI($retVal);
	}
	$userInfo = $userObj->getInfo();
	$stickyObj = new Sticky($rwConn, $userInfo);
	if(!in_array($method,get_class_methods($stickyObj))){
		$retVal['message'] = 'Invalid API call.';
		returnAPI($retVal);
	}

	$methodReturn = $stickyObj->$method();
	if(isset($methodReturn['success'])){
		$retVal['success'] = $methodReturn['success'];
		unset($methodReturn['success']);
	}
	if(isset($methodReturn['message'])){
		$retVal['message'] = $methodReturn['message'];
		unset($methodReturn['message']);
	}

	$retVal = array_merge($retVal,$methodReturn);
	returnAPI($retVal);

?>
